package com.example.mobile2021606127cxz0406;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private Button btnMainCreate;
    private RadioGroup radGupCarLine;
    private RadioButton radBtnMainLine1;
    private RadioButton radBtnMainLine2;
    private RadioButton radBtnMainLine3;
    private RadioButton radBtnMainLine4;
    private TextView tvMainTitle;
    private RadioGroup radGupCarType;
    private RadioButton radBtnMainSaloon;
    private RadioButton radBtnMainMPV;
    private RadioButton radBtnMainSUV;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        radGupCarType.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int i) {
                RadioButton radioButton = findViewById(i);
                Log.i("RadioButton", radioButton.getText().toString());
            }
        });
        radGupCarLine.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int i) {
                RadioButton radioButton = findViewById(i);
                Log.i("RadioButton", radioButton.getText().toString());
            }
        });
        btnMainCreate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String msg = "";
                int carId = radGupCarType.getCheckedRadioButtonId();
                if (carId != -1) {
                    msg = ((RadioButton) findViewById(carId)).getText().toString();
                } else {
                    msg = "未选车型";
                }
                int lineId = radGupCarLine.getCheckedRadioButtonId();
                if (lineId != -1) {
                    msg +="，"+ ((RadioButton) findViewById(lineId)).getText().toString();
                } else {
                    msg += "，未选生产线";
                }

                Log.i("点击按钮", msg);
            }
        });
    }

    private void initView() {
        btnMainCreate = (Button) findViewById(R.id.btn_main_create);
        radGupCarLine = (RadioGroup) findViewById(R.id.radGup_car_line);
        radBtnMainLine1 = (RadioButton) findViewById(R.id.radBtn_main_line1);
        radBtnMainLine2 = (RadioButton) findViewById(R.id.radBtn_main_line2);
        radBtnMainLine3 = (RadioButton) findViewById(R.id.radBtn_main_line3);
        radBtnMainLine4 = (RadioButton) findViewById(R.id.radBtn_main_line4);
        tvMainTitle = (TextView) findViewById(R.id.tv_main_title);
        radGupCarType = (RadioGroup) findViewById(R.id.radGup_car_type);
        radBtnMainSaloon = (RadioButton) findViewById(R.id.radBtn_main_saloon);
        radBtnMainMPV = (RadioButton) findViewById(R.id.radBtn_main_MPV);
        radBtnMainSUV = (RadioButton) findViewById(R.id.radBtn_main_SUV);
    }
}